Answer:

JLabel fatLabel    with    JTextField inFat

JLabel calLabel    with    JTextField inCal

JLabel perLabel    with    JTextField outPer

Adding Components to a JPanel

The idea is to have three panels, one for each pair of label and text field. The lone title at the top and the button at the bottom do not need to be placed in panels. The picture shows this grouping. (The lines showing the panels do not actually appear.)

GUI with panels

The add() method places components in a panel. Each panel needs a layout manager. This program uses the default layout manager, FlowLayout, for each panel.

public class percentFatPan extends JFrame implements ActionListener
{
  JLabel title    = new JLabel("Percent of Calories from Fat");
  JLabel fatLabel = new JLabel("Enter grams of fat:   ");
  JLabel calLabel = new JLabel("Enter total calories: ");
  JLabel perLabel = new JLabel("Percent calories from fat: ");

  JTextField inFat  = new JTextField( 7 );
  JTextField inCal  = new JTextField( 7 );
  JTextField outPer = new JTextField( 7 );

  JButton    doit   = new JButton("Do It!");

  JPanel fatPanel   = new JPanel();
  JPanel calPanel   = new JPanel();
  JPanel perPanel   = new JPanel();
  
  public percentFatPanel()   
  {  
    fatPanel.add(  );
    fatPanel.add(  );
    calPanel.add(  );
    calPanel.add(  );
    perPanel.add(  );
    perPanel.add(  );
  
   . . . . .
 }

QUESTION 5:

Fill in the blanks by clicking the buttons. Think a little, first.